//package com.xjh.config;
//
///**
// * @author XuJianHua
// * @version 1.0
// * @company 湖南安第斯信息科技有限公司, 版权所有
// * @date 2022/7/26 14:31
// */
//
//import org.springframework.context.annotation.Configuration;
//import org.springframework.security.config.annotation.web.builders.HttpSecurity;
//import org.springframework.security.config.http.SessionCreationPolicy;
//import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer;
//import org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfigurerAdapter;
//import org.springframework.security.oauth2.config.annotation.web.configurers.ResourceServerSecurityConfigurer;
//import org.springframework.security.oauth2.provider.token.DefaultTokenServices;
//import org.springframework.security.oauth2.provider.token.RemoteTokenServices;
//import org.springframework.security.oauth2.provider.token.ResourceServerTokenServices;
//
///**
// * 描述：资源管理器 @EnableResourceServer，extends ResourceServerConfigurerAdapter
// * 为了模拟，授权服务器和资源服务器放在了一起，正常情况是解耦的。
// */
//@Configuration
//@EnableResourceServer //开启资源服务器
//public class ResourceServerConfig extends ResourceServerConfigurerAdapter {
//
//    public static final String RESOURCE_SALARY = "test";
//
//    @Override
//    public void configure(HttpSecurity http) throws Exception {
//        http.authorizeRequests() //校验请求
//                .antMatchers("/test/**") // 路径匹配规则。
//                .access("#oauth2.hasScope('all')") // 需要匹配scope
//                .and().csrf().disable().sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS);
//    }
//
//    @Override
//    public void configure(ResourceServerSecurityConfigurer resources) throws Exception {
//        resources.resourceId(RESOURCE_SALARY) //资源ID
//                .tokenServices(tokenServices()) //  使用远程服务验证令牌的服务
//                .stateless(true); //无状态模式
//
//    }
//
//    // 配置access_token远程验证策略(验证token是否有效)
//    public ResourceServerTokenServices tokenServices() {
////        DefaultTokenServices services = new DefaultTokenServices();
//        RemoteTokenServices services = new RemoteTokenServices();
//        services.setCheckTokenEndpointUrl("http://localhost:8888/oauth/check_token");
//        services.setClientId("client");
//        services.setClientSecret("123456");
//        return services;
//    }
//}
